<?php
namespace App\Logic\ZiNiao\Work\PlansPost;

use App\Logic\ZiNiao\Api\PlansPost;
use App\Logic\ZiNiao\Work\Helper;
use App\Models\ZiNiao\PlansPost as PlansPostModel;
class PerformanceNotice
{
    public static function exe($date = '')
    {
        $_date = $date ? $date : date('Y-m-d',strtotime("-1 days"));
        $s_time = strtotime($_date);
        $sTime = msectime($s_time);
        $e_time = $s_time + 24 * 3600 - 1;
        $eTime = msectime($e_time);
        $example = new PlansPost();
        $name = "业绩通知详情明细$_date";
        $scriptList = [
            [
                "scriptId" => "1361",
                "runWith" => [
                    [
                        "name" => "daterange",
                        "value" => "$sTime,$eTime"
                    ]
                ]
            ]
        ];
        $bizContent = [
            "name" => $name,
            "platformId" => "0",//亚马逊
            "actionType" => "AT_ONCE",
            "scriptList" => $scriptList,
            "storeScopeType" => "ASSIGNED",
            "storeAndMarketPlaceList" => Helper::storeAndMarketPlaceList(),
        ];
        $data = $example->exe($bizContent);
        if(!$data)return 0;
        PlansPostModel::query()->create(
            [
                'name' => $name,
                'platformId' => 0,
                'scriptList' => $scriptList,
                's_date' => $_date,
                'e_date' => $_date,
                'planId' => $data->planId,
            ]
        );
        return 1;
    }
}
